import os
from dotenv import load_dotenv
import requests

"""
deepseek对话
"""
# 加载 .env 文件中的环境变量
dotenv_path = os.path.join(os.path.dirname(__file__), '../.env')
load_dotenv(dotenv_path=dotenv_path)

api_key = os.getenv("DASHSCOPE_API_KEY")
# print(api_key)
if not api_key:
    raise ValueError("DASHSCOPE_API_KEY is not set in the environment variables.")

URL = "http://localhost:11434/api/generate"

headers = {
    "Content-Type": "application/json"
}


def call_ollama_generate(prompt, model="deepseek-r1:14b", system=None):
    payload = {
        "model": model,
        "stream": False,
        "prompt": prompt,
        "system": system,

    }

    response = requests.request("POST", URL, json=payload, headers=headers)
    return response.json()['response']


if __name__ == "__main__":
    response = call_ollama_generate("为什么天空是蓝的")
    print(response)


